package com.llxz.blog.article.util;

import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author zzh & lyq
 * @description:. date: 2021/9/7 10:15
 */


public class PageHelper {
    public <T> PageImpl<T> listConvertToPage(List<T> list, Pageable pageable) {
        int start = (int)pageable.getOffset();
        int end = (start + pageable.getPageSize()) > list.size() ? list.size() : ( start + pageable.getPageSize());
        return new PageImpl<T>(list.subList(start, end), pageable, list.size());
    }
}
